<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
	<title></title>
	<link href="/admin/styles/general.css" rel="stylesheet" type="text/css" />
	<link href="/admin/styles/main.css" rel="stylesheet" type="text/css" />
	<script type="text/javascript" src="/admin/js/utils.js"></script>

	<script type="text/javascript" src="/admin/js/jquery.1.12.js"></script>

	<script type="text/javascript" src="/admin/js/jquery.js"></script>

	<script type="text/javascript" src="/admin/js/selectzone.js"></script>
	<script type="text/javascript" src="/admin/js/colorselector.js"></script>
	<script type="text/javascript" src="/admin/js/calendar.php?lang="></script>
	<script type="text/javascript" charset="utf-8" src="/admin/ueditor/ueditor.config.js"></script>
	<script type="text/javascript" charset="utf-8" src="/admin/ueditor/ueditor.all.min.js"> </script>
	<script type="text/javascript" charset="utf-8" src="/admin/ueditor/lang/zh-cn/zh-cn.js"></script>

  <style type="text/css">
    .ulColumn2{overflow:hidden;}
    .ulColumn2 li{margin:15px 0;}
    .ulColumn2 li .item_name{text-align:right;display:inline-block;}
    .attr-select{width: 143px;}
    li{list-style-type:none;}
  </style>

</head>
<body>
<h1>
	<span class="action-span"><a href="goods_list">商品列表</a></span>
	<span class="action-span1"><a href="index.php?act=main">SHOP 管理中心 </a> </span><span id="search_id" class="action-span1"> - 编辑商品信息 </span>
	<div style="clear:both"></div>
</h1>

<div class="tab-div">
    <!-- tab bar -->
    <div id="tabbar-div">
      <p>
        <span class="tab-front" id="general-tab">通用信息</span>
      	<span class="tab-back" id="detail-tab">详细描述</span>
      	<span class="tab-back" id="mix-tab">其他信息</span>
      	<span class="tab-back" id="properties-tab">商品属性</span>
      	<span class="tab-back" id="gallery-tab">商品相册</span>
      </p>
    </div>

    <!-- tab body -->
    <div id="tabbody-div">
      <form enctype="multipart/form-data" action="goods_add" method="post"> 
      <input type="hidden" name="_token" value="<?php echo csrf_token(); ?>">
        <input type="hidden" name="MAX_FILE_SIZE" value="2097152">
		 <!-- 通用信息 -->
        <table width="90%" id="general-table" align="center" style="display: table;">
			<tbody>
				<tr>
					<td class="label">商品名称：</td>
					<td><input type="text" name="goods_name" size="30"><span class="require-field">*</span></td>
				</tr>
				<tr>
					<td class="label">商品货号： </td>
					<td><input type="text" class="textbox textbox_295" placeholder="商品货号..." size="20" name="goods_sn">
					<input type="button" class="link_btn get-goods-sn" value="生成货号"/>
          </td>
			</tr>
			<tr><td class="label">商品分类：</td>
				<td><select name="cate_id"><option value="0">请选择...</option>
            @foreach ($cateList as $k=>$v)
						  <option value="{{$v->cate_id}}">{{$v->level}}{{$v->cate_name}}</option>
						@endforeach</td>
      </tr>
			<tr>
				<td class="label">商品品牌：</td>
				<td><select name="brand_id">
						<option value="0">请选择...</option>
            <?php foreach ($brandList as $key => $value): ?>
						<option value="{{$value->brand_id}}">{{$value->brand_name}}</option>
            <?php endforeach ?></select>
				</td>
			</tr>

     
      <tr>

				<td class="label">本店售价：</td>
				<td><input type="text" name="shop_price" size="20">
			</tr>

       <tr>
        <td class="label">市场售价：</td>
        <td><input type="text" name="goods_price" size="20">
      </tr>
      <tr>
        <td class="label">排序：</td>
        <td><input type="text" name="sort" size="20">
      </tr>
      <tr>
        <td class="label">上传商品图片：</td>
        <td>
          <input type="file" name="goods_img" size="35">
            <a href="goods.php?act=show_image&amp;img_url=images/200905/goods_img/32_G_1242110760868.jpg" target="_blank"><img src="/admin/images/yes.gif" border="0"></a><br>
            <input type="text" size="40" value="商品图片外部URL" style="color:#aaa;" onfocus="if (this.value == '商品图片外部URL'){this.value='http://';this.style.color='#000';}" name="goods_img_url">
        </td>
      </tr>

        </tbody></table>
        <!-- 详细描述 -->
        <table width="90%" id="detail-table" style="display: none;">
          <tbody><tr>
            <td>

            	<textarea name="goods_desc" id="goods_desc" cols="170" rows="10"></textarea>
            </td>

          </tr>
        </tbody></table>
        <!-- 其他信息 -->
        <table width="90%" id="mix-table" style="display: none;" align="center">

         <tbody>
          <tr>

            <td class="label"><a href="javascript:showNotice('noticeStorage');" title="点击此处查看提示信息"><img src="/admin/images/notice.gif" width="16" height="16" border="0" alt="点击此处查看提示信息"></a> 商品库存数量：</td>
            <td><input type="text" name="goods_number" size="20"><br>
            <span class="notice-span" style="display:block" id="noticeStorage">库存在商品为虚货或商品存在货品时为不可编辑状态，库存数值取决于其虚货数量或货品数量</span></td>
          </tr>

          <tr>
            <td class="label">加入推荐：</td>
            <td><input type="checkbox" name="is_best" value="1" checked="checked">精品 <input type="checkbox" name="is_new" value="1"checked="checked">新品 <input type="checkbox" name="is_hot" value="1" checked="checked">热销</td>
          </tr>
          <tr id="alone_sale_1">

            <td class="label" id="alone_sale_2" checked="checked"> 上架：</td>
            <td id="alone_sale_3"><input type="checkbox" name="is_on_sale" value="1"> 打勾表示允许销售，否则不允许销售。</td>
          </tr>

        </tbody></table>
        <!-- 商品属性 -->
      <table width="90%" id="properties-table" style="display: none;" align="center">
			<tbody>
				<tr>
					<td class="label">商品类型：</td>
					<td>
						<select class="select type-select" name="type_id">
							<option value="0">请选择商品类型</option>
							<?php foreach ($typeList as $key => $value): ?>
								<option value="<?php echo $value['type_id'] ?>"><?php echo $value['type_name'] ?></option> 
							<?php endforeach ?>              
						</select><br>

					</td>
				</tr>
				<tr>
        <td id="tbody-goodsAttr" colspan="2" style="padding:0">
          <table width="100%" id="attrTable">
            <ul class="ulColumn2 attr-box"></ul>
          </table>
          </td>
        </tr>
    </tbody>
	</table>
        <!-- 商品相册 -->
        <table width="90%" id="gallery-table" style="display: none;" align="center">
          <tbody><tr>
            <td>
              <li>
                <span class="item_name add-photo" style="width:120px;">[+]</span>
                <input type="file" name="goods_photo[]"/>
                <input type="text" class="textbox" placeholder="图片名称..." name="goods_photo_name[]"/>
              </li>
              <!-- <li>
                  <span class="item_name add-file-input" style="width:120px;">[+]</span>
                  <input type="file" name="goods_photo[]" class="goods_photo"/><input type="text" name="img_desc[]" />
              </li> -->
            </td>
          </tr>
        </tbody></table>

        <div class="button-div">
          <input type="hidden" name="goods_id" value="32">
          <input type="submit" value=" 确定 " class="button">
          <input type="reset" value=" 重置 " class="button">
        </div>
        <input type="hidden" name="act" value="update">
      </form>
    </div>
</div>


<div id="footer">
	版权所有 &copy; 2006-2013 
</div>
<script type="text/javascript" src="/admin/js/tab.js"></script>
<script>
    $('.add-photo').click(function(){
     var li=$(this).parents('li').clone();
        li.find('.add-photo').text('[-]').removeClass('add-photo').addClass('del-photo');
        $(this).parents('li').after(li);
    });
    $(document).on('click','.del-photo',function(){
        $(this).parents('li').detach();
    })
</script>
<script type="text/javascript">

	//实例化百度编辑器
	//var ue = UE.getEditor('goods_desc');
 // 	// 根据类型获取属性列表


	function addImg(obj){
      var src  = obj.parentNode.parentNode;
      var idx  = rowindex(src);
      var tbl  = document.getElementById('gallery-table');
      var row  = tbl.insertRow(idx + 1);
      var cell = row.insertCell(-1);
      cell.innerHTML = src.cells[0].innerHTML.replace(/(.*)(addImg)(.*)(\[)(\+)/i, "$1removeImg$3$4-");
  	}

    function removeImg(obj){
      var row = rowindex(obj.parentNode.parentNode);
      var tbl = document.getElementById('gallery-table');
      tbl.deleteRow(row);
  	}

   	function dropImg(imgId){
    	Ajax.call('goods.php?is_ajax=1&act=drop_image', "img_id="+imgId, dropImgResponse, "GET", "JSON");
  	}

  	function dropImgResponse(result){
      if (result.error == 0){
          document.getElementById('gallery_' + result.content).style.display = 'none';
      }
  	}

</script>
<script type="text/javascript">
        $('.type-select').change(function(){
            var type_id = $(this).val();
            $.ajax({
                type: 'get',
                url: "getAttr/"+type_id,
                dataType: 'json',
                success: function(result){
                    $('.attr-box').html('');
                    $.each(result, function(k, v){
                        var li = $('<li></li>');
                        if(v.attr_type == 1){
                            //规格：可多选 +    有价格
                            li.append('<span class="item_name" style="width:120px;"><span class="add-attr">[+]</span>'+v.attr_name+'： </span>');
                            if(v.attr_input_type == 1){
                                //下拉选择
                                var select = $('<select class="select attr-select" name="attr_value['+v.attr_id+'][]"></select>');
                                select.append('<option value="">请选择</option>');
                                var attr_value = v.attr_value.split('|');
                                $.each(attr_value, function(kk, vv){
                                    select.append('<option>'+vv+'</option>');
                                });
                                li.append(select);
                                
                            }else{
                                //手动输入 /文本框
                                li.append('<input type="text" class="textbox attr-input" name="attr_value['+v.attr_id+'][]" placeholder="属性值..."/>');
                            }
                            li.append('<input type="text" class="textbox" name="attr_price['+v.attr_id+'][]" placeholder="属性价格..."/>');
                        }else{
                            //参数：
                            li.append('<span class="item_name" style="width:120px;">'+v.attr_name+'： </span>');
                            if(v.attr_input_type == 1){
                                //下拉选择
                                var select = $('<select class="select attr-select" name="attr_value['+v.attr_id+']"></select>');
                                var attr_value = v.attr_value.split('|');
                                $.each(attr_value, function(kk, vv){
                                    select.append('<option>'+vv+'</option>');
                                });
                                li.append(select);

                            }else{
                                //手动输入 文本框
                                li.append('<input type="text" class="textbox attr-input" name="attr_value['+v.attr_id+']" placeholder="属性值..."/>');
                            }
                        }
                        $('.attr-box').append(li);
                    });
                }
            });
        });
        
        $(document).on('click', '.add-attr', function(){
            var li = $(this).parent().parent();
            var html = li.clone();
            html.find('.add-attr').text('[-]').removeClass('add-attr').addClass('del-attr');
            li.after(html);
        });
        $(document).on('click', '.del-attr', function(){
            $(this).parent().parent().remove();
        });
</script>
<script>
    $('.get-goods-sn').on('click',function(){
        var input=$('.textbox_295');
        // alert(input);
        $.ajax({
            type:"get",
            url:"getGoodsSn",
            dataType:"json",
            success:function(res){
             // alert(res);
                input.val(res);
            }
        })
    })
</script>
<script type="text/javascript">
    $('.add-file-input').click(function () {
        var li = $(this).parent();
        var new_li = li.clone();
        new_li.find('.add-file-input').text('[-]').removeClass('add-file-input').addClass('del-file-input');
        li.after(new_li);
    });

    $(document).on('click', '.del-file-input', function () {
        $(this).parent().detach();
    });
</script>
</body>
</html>